package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import com.lagou.edu.service.impl.ResumeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/list")
    public String list(){
        return "resumeList";
    }

    @ResponseBody
    @RequestMapping("/getList")
    public List<Resume> getList(){
        return resumeService.getList();
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public @ResponseBody String add(@RequestBody Resume resume) {
        try {
            resumeService.add(resume);
            return "success";
        }catch (Exception e){
            e.printStackTrace();
            return "failed";
        }
    }

    @RequestMapping(value = "edit", method = RequestMethod.POST)
    public @ResponseBody String edit(@RequestBody Resume resume) {
        try {
            resumeService.update(resume);
            return "success";
        }catch (Exception e){
            e.printStackTrace();
            return "failed";
        }
    }

    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public @ResponseBody String delete(@RequestBody Resume resume) {
        try {
            resumeService.delete(resume);
            return "success";
        }catch (Exception e){
            e.printStackTrace();
            return "failed";
        }
    }
}
